package com.feng.algorithm;

/**
 * @author feng
 * @decrition
 * @date 2022/3/2423:13
 */
public class Sort {
    public static void main(String[] args) {
        int i = 0;
        int x = 0;
        int y = 0;
        String[] arr = {"y", "x", "-y", "-x"};
        String str = "LGG";
        char[] array = str.toCharArray();
        for (int j = 0; j < array.length; j++) {
            if ('L' == array[j]) {
                i -= 1;
            } else if ('R' == array[j]){
                i += 1;
            }
            if (i < 0) {
                i = arr.length + i;
            }
            if (i > 3) {
                i = i % 4;
            }
            if ('G' == array[j]) {
                String s = arr[i];
                switch (s) {
                    case "x":
                       x += 1;
                       break;
                    case "-y":
                        y -= 1;
                        break;
                    case "-x":
                        x -= 1;
                        break;
                    case "y":
                        y += 1;
                        break;
                }
            }
        }
        System.out.println("(" + x + "," + y + ")");

        /*int[] nums = {1,3,5,7,2,56,54,7,34,6,453,56,45,34,45,564,345,65,345,4564,5};
        long start = System.currentTimeMillis();
//        bubbleSort(nums);
//        selectionSort(nums);
//        insertionSort(nums);
        System.out.println(System.currentTimeMillis() - start);
        for (int i = 0; i < nums.length; i++) {
            System.out.print(nums[i] + "    ");
        }*/
    }

    /**
     * 冒泡排序
     * 相邻两个比较 比大小 交换
     * 时间复杂度：O(n^2)
     *
     * @param nums 待排序数组
     */
    public static void bubbleSort(int[] nums) {
        for (int i = 0; i < nums.length; i++) {
            for (int j = i+1; j < nums.length; j++) {
                if (nums[i] > nums[j]) {
                    swap(nums, i, j);
                }
            }
        }
    }

    /**
     * 选择排序
     * 先选出最值 与待排序数组交换
     * 时间复杂度：O(n^2)
     * 与冒泡排序相比，主要是减少了交换次数 冒泡排序交换大于n次， 选择排序最多交换n次
     *
     * @param nums 待排序数组
     */
    public static void selectionSort(int[] nums) {
        int min = 0;
        for (int i = 0; i < nums.length; i++) {
            min = i;
            for (int j = i + 1; j < nums.length; j++) {
                if (nums[min] > nums[j]) {
                    min = j;
                }
            }
            if (i != min) {
                swap(nums, i, min);
            }
        }
    }

    /**
     * 插入排序
     * 与局部有序的数组比较在排序
     * 时间复杂度:O(n^2)  比冒泡排序快一倍，比选择排序略快
     *
     * @param nums 待排序数字
     */
    public static void insertionSort(int[] nums) {
        for (int i = 1; i < nums.length; i++) {
            int temp = nums[i];
            int j = i;
            for (; j > 0 && nums[j - 1] >= temp; j--) {
                nums[j] = nums[j-1];
            }
            nums[j] = temp;
        }
    }

    /**
     * 交换法
     *
     * @param nums 数组
     * @param i 索引
     * @param j 索引
     */
    private static void swap(int[] nums, int i, int j) {
        int temp = nums[i];
        nums[i] = nums[j];
        nums[j] = temp;
    }

}
